//
//  M2LunchAd.m
//  m2048
//
//  Created by lcb on 5/5/15.
//  Copyright (c) 2015 lcb. All rights reserved.
//

#import "M2LunchAd.h"
#import "BaiduMobAdSplash.h"
#import "BaiduMobAdSplashDelegate.h"
@interface M2LunchAd ()<BaiduMobAdSplashDelegate>
@property (strong, nonatomic) BaiduMobAdSplash *splash;
@end
@implementation M2LunchAd
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self commonInit];
    }
    return self;
}


- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        [self commonInit];
    }
    return self;
}
- (void)commonInit
{
    self.backgroundColor = [UIColor clearColor];
    // 全屏开屏
    BaiduMobAdSplash *splash = [[BaiduMobAdSplash alloc] init];
    splash.delegate = self;
    splash.canSplashClick = YES;
    splash.useCache = YES;
    splash.backgroundColor=[UIColor clearColor];
    [splash loadAndDisplayUsingContainerView:self];
    self.splash = splash;
}
- (NSString *)publisherId
{
    return @"ce7235ab";
}

- (NSString*) appSpec
{
    return @"ce7235ab";
}

/**
 *  广告展示结束
 */
- (void)splashDidDismissScreen:(BaiduMobAdSplash *)splash {
    //自定义开屏移除
     NSLog(@"自定义开屏移除");
    self.hidden = YES;
    [self removeFromSuperview];
}

-(BOOL) enableLocation
{
    //启用location会有一次alert提示
    return NO;
}
/**
 *  广告展示成功
 */
- (void)splashSuccessPresentScreen:(BaiduMobAdSplash *)splash
{
      NSLog(@"广告展示成功");
}

/**
 *  广告展示失败
 */
- (void)splashlFailPresentScreen:(BaiduMobAdSplash *)splash withError:(BaiduMobFailReason) reason
{
    //自定义开屏移除
    NSLog(@"自定义开屏移除");
     self.hidden = YES;
    [self removeFromSuperview];
}

@end
